// 访问量趋势图表初始化
function initVisitChart() {
    const ctx = document.getElementById('visitChart').getContext('2d');
    
    // 从HTML元素中提取数据
    const dayElements = document.querySelectorAll('.visit-day');
    const labels = Array.from(dayElements).map(el => el.getAttribute('data-date'));
    const counts = Array.from(dayElements).map(el => parseInt(el.getAttribute('data-count')));
    
    new Chart(ctx, {
        type: 'line',
        data: {
            labels: labels,
            datasets: [{
                label: '访问量',
                data: counts,
                borderColor: '#3498db',
                backgroundColor: 'rgba(52, 152, 219, 0.1)',
                borderWidth: 2,
                tension: 0.3,
                fill: true
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: false
                },
                tooltip: {
                    mode: 'index',
                    intersect: false,
                    callbacks: {
                        label: function(context) {
                            return `访问量: ${context.parsed.y}`;
                        }
                    }
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    ticks: {
                        stepSize: 1
                    }
                }
            }
        }
    });
}

// 页面加载完成后初始化图表
document.addEventListener('DOMContentLoaded', function() {
    if (typeof Chart !== 'undefined' && document.getElementById('visitChart')) {
        initVisitChart();
    }
});